package cn.edu.seu.herald.informationplatform.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.seu.herald.informationplatform.bean.league.Activity;
import cn.edu.seu.herald.informationplatform.bean.league.LeagueInfo;
import cn.edu.seu.herald.informationplatform.dao.database.ActivityDao;
import cn.edu.seu.herald.informationplatform.dao.database.LeagueInfoDao;

public class Test extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public Test() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		PrintWriter out = response.getWriter();
		
		LeagueInfoDao access = LeagueInfoDao.getDao();
		try {
			LeagueInfo league = access.getLeagueInfo(2);
			out.println(league.getName());
		} catch (SQLException e) {
		}
		
		//leagueUserDao.addLeagueUser(newLeagueUser);
		//leagueUserDao.deleteLeagueUser(2);
		//LeagueUser leagueUser=leagueUserDao.getLeagueUser(1);
		//out.println(leagueUser.getUsername());
		//leagueUserDao.updateLeagueUser(2, newLeagueUser);
 //ActivityDao activityDao=ActivityDao.getDao();
 //out.println(activityDao.getActivityByLeagueId(2).keySet().size());
		
		
		//ActivityDao activityDao=ActivityDao.getDao();
		//Activity newActivity=new Activity(1,"讲座", "18号", "19号", "哈哈","www", "234234", "herald", 2);
		//activityDao.insertActivity(newActivity);
		//activityDao.deleteActivity(2);
		
		//ActivityClassDao activityClassDao=ActivityClassDao.getDao();
		//activityClassDao.addActivityClass("讲座");
		//activityClassDao.deleteActivityClass(1);
		/*HashMap<Integer, String> map;
		try {
			map = activityClassDao.getActivityClassMap();
			Iterator iter = map.keySet().iterator();
			Integer id=0;
			while(iter.hasNext()){
		        id=(Integer) iter.next();
				out.print(id.toString());
				out.print(map.get(id));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		*/
		ActivityDao activityDao=ActivityDao.getDao();
		Activity newActivity=new Activity();
		newActivity.setInformation("hehe");
		try {
			System.out.println(activityDao.addActivity(newActivity));
			System.out.println("row"+activityDao.hasId(4));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out
				.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
		out.println("<HTML>");
		out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
		out.println("  <BODY>");
		out.print("    This is ");
		out.print(this.getClass());
		out.println(", using the POST method");
		out.println("  </BODY>");
		out.println("</HTML>");
		out.flush();
		out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
